package com.order.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class DeskDBUtil {
	static Connection con=null;
	public static List<String[]> getAllDeskIdAndNo(){
		//int count=getAllNum();
		List<String[]> list=new ArrayList<String[]>();
		   try{
			    con=DBConnection.getConnect();
				Statement st=con.createStatement();
				String sql="select deskid,deskno from desk";
				ResultSet rs=st.executeQuery(sql);
				//int i=0;
				while(rs.next()){
					String str[]=new String[2];
					str[0]=rs.getString(1);
					str[1]=rs.getString(2);
					//i++;
					list.add(str);
				}
				rs.close();
				st.close();
				con.close();
		   }catch(Exception e){
			   e.printStackTrace();
		   }
		   return list;
	   }
	public static int getAllNum(){
	 	int num=0;
	 	try{
	 		//Class.forName(driver);
	 		con=DBConnection.getConnect();
	 		Statement st=con.createStatement();
	 		String sql="select count(*) from  desk";
	 		ResultSet rs=st.executeQuery(sql);
	 		if(rs.next()){
	 			num=rs.getInt(1);
	 		}
	 		rs.close();
			st.close();
			con.close();
	 	}catch(Exception e){
	 		e.printStackTrace();
	 	}
	 	return num;
	 }
	public static String getidByno(String deskno){
		String deskid=null;
	 	try{
	 		//Class.forName(driver);
	 		con=DBConnection.getConnect();
	 		Statement st=con.createStatement();
	 		String sql="select deskid from desk where deskno= '"+deskno+"'";
	 		ResultSet rs=st.executeQuery(sql);
	 		if(rs.next()){
	 			deskid=rs.getString(1);
	 		}
	 		rs.close();
			st.close();
			con.close();
	 	}catch(Exception e){
	 		e.printStackTrace();
	 	}
	 	return deskid;
	}
}
